{include file="public/head"}

<body>
<div id="wrapper">

    <div class="gray-bg dashbard-1">
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <div class="form-horizontal m-t">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">应用标题：</label>
                                    <div class="col-sm-8">
                                        <input id="name" name="name" maxlength="255" type="text" class="form-control" required="" aria-required="true" value="{$AppInfo.name}">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">应用Logo：</label>
                                    <div class="col-sm-8">
                                        <label for="logo_url">
                                            <img id="m_logo_url" src="{$AppInfo.logo_url}" onerror="this.src='/static/Admin/img/no_img.png'" style="max-width:  80px">
                                            <input type="file" id="logo_url" class="upload_pic" style="display: none;">
                                        </label>
                                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> Logo尺寸：80*80</span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">是否显示：</label>
                                    <div class="col-sm-8">
                                        <select id="is_show" class="form-control">
                                            <option value="0" {if condition="$AppInfo.is_show eq 0"}selected{/if}>否</option>
                                            <option value="1" {if condition="$AppInfo.is_show eq 1"}selected{/if}>是</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">公告内容：</label>
                                    <div class="col-sm-8">
                                        <script id="content" type="text/plain" style="width:100%;height:400px;">{$AppInfo.content}</script>
                                    </div>
                                </div>

                                <input type="hidden" id="id" value="{$AppInfo.id}"/>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-3">
                                        <button class="btn btn-primary" type="button" id="sub">保存</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>
<script src="__STATIC__/Admin/js/jquery-2.1.1.min.js"></script>
<script src="__STATIC__/Admin/js/bootstrap.min.js?v=3.4.0"></script>
<script src="__STATIC__/Admin/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="__STATIC__/Admin/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/Admin/layer/layer.js"></script>
<script src="__STATIC__/Admin/ueditor/1.4.3/ueditor.config.js"></script>
<script src="__STATIC__/Admin/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script src="__STATIC__/Admin/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script>
    var editor = new UE.ui.Editor();
    editor.render("content");

    //ajax异步图片上传
    $('.upload_pic').change(function(){
        //图片对象
        let that = $(this);
        var formData = new FormData();
        formData.append("image", that[0].files[0]);

        // 上传设置
        $.ajax({
            // 规定把请求发送到那个URL
            url: "{:url('App/forUpload')}",
            type: "post",            // 请求方式
            dtaType: 'json',
            data: formData,//传值就传fd对象了
            processData:false,  //告诉jQuery不要处理数据
            contentType: false,  //告诉jQuery不要设置contentType
            // 请求成功时执行的回调函数
            success: function (data) {
                if(data.status == 1)
                {
                    that.prev().attr('src',data.message);
                }
                else
                {
                    alert(data.message);
                }
            }
        });
    });

    $("#sub").on('click',function(){
        var name = $('#name').val();
        var logo_url = $('#m_logo_url').attr('src');
        var is_show = $('#is_show').val();
        var content = editor.getContent();

        if(name == ''){
            layer.msg('请输入应用标题',{icon: 5,time:1500});
            return false;
        }

        if(logo_url == '/static/Admin/img/no_img.png'){
            layer.msg('请上传应用Logo',{icon: 5,time:1500});
            return false;
        }

        if(content == ''){
            layer.msg('请输入应用内容',{icon: 5,time:1500});
            return false;
        }

        $.ajax({
            type:"POST",
            url:"{:url('App/AppEdit')}",
            data:{
                id:$("#id").val(),
                name:name,
                logo_url:logo_url,
                is_show:is_show,
                content:content,
            },
            dataType:"json",
            success:function(data){
                if(data.status == 1){
                    layer.msg(data.message, {icon: 6,time:1500},function () {
                        window.top.location.reload();
                    });
                }else{
                    layer.msg(data.message,{icon: 5,time:1500});
                }
            }
        });
    })
</script>
</body>

</html>
